import axiosInstance from '@/utils/http'

export interface User {
  id: number
  avatar: string
  username: string
  nickname: string
  password: string
  createTime: Date
  updateTime: Date
  order: string
  prop: string
}

export function getInfo(): Promise<R<UserInfo>> {
  return axiosInstance.get<R<UserInfo>>('/user')
}

export function create(data: User): Promise<R<User>> {
  return axiosInstance.post<R<User>>('/user', { data })
}
export function getById(id: number): Promise<R<User>> {
  return axiosInstance.get<R<User>>(`/user/${id}`)
}

export function updateById(data: User): Promise<R<User>> {
  return axiosInstance.put<R<User>>(`/user`, { data })
}

export function deleteById(id: number): Promise<R<User>> {
  return axiosInstance.delete<R<User>>(`/user/${id}`)
}

export function deleteByIds(data: number[]): Promise<R<User>> {
  return axiosInstance.delete<R<User>>(`/user`, { data })
}

export function getList(data: User): Promise<R<User[]>> {
  return axiosInstance.post<R<User[]>>('/user/list', { data })
}
export function count(data: User): Promise<R<number>> {
  return axiosInstance.post<R<number>>('/user/count', { data })
}

export function page(data: User, page: number, size: number): Promise<R<User[]>> {
  return axiosInstance.post<R<User[]>>(`/user/${page}/${size}/page`, { data })
}
